# gozerbot/aliases.py
#
#

""" command aliases """

__copyright__ = 'this file is in the public domain'

from gozerbot.datadir import datadir
from gozerbot.persist import Persist

aliases = Persist(datadir + '/aliases') # aliases
if not aliases.data:
    aliases.data = {}

def aliasreverse(what):
    """ get the reverse of an alias """
    for i, j in aliases.data.iteritems():
        if j == what:
            return i

def aliascheck(ievent):
    """ check if alias is available """
    try:
        cmnd = ievent.txt.split()[0]
        alias = aliases.data[cmnd]
        ievent.txt = ievent.txt.replace(cmnd, alias, 1)
    except:
        pass
